#!/bin/sh
# echo -e "Content-type: text/plain\n\n"

#-----lqu modify 20120816
#COMMON_CONF=../fh_common.conf
COMMON_CONF=/etc/fh_common.conf
FHBOX_PATH=`grep "FHBOX_BIN_PATH=" $COMMON_CONF | cut -d = -f 2 `
SETCFG=`grep "MISC_SHELL_PATH_SETCFG=" $COMMON_CONF | cut -d = -f 2 `
GETCFG=`grep "MISC_SHELL_PATH_GETCFG=" $COMMON_CONF | cut -d = -f 2 `
INTER_WEB=$FHBOX_PATH/inter_web
MOREMGT=$FHBOX_PATH/moremgt
MISC_CONF_PATH=`grep "MISC_CONF_PATH=" $COMMON_CONF | cut -d = -f 2 `
AREA_PATH=`grep "PRODUCT_CONF_PATH_TR069_CONTROL=" $COMMON_CONF | cut -d = -f 2 `
area=`grep "area_code=" $AREA_PATH | cut -d = -f 2 `

CGI_PATH=/var/WEB-GUI/cgi-bin/
if [ -f $CGI_PATH/../hgcxml_wlanf.conf ];then
	. $CGI_PATH/../hgcxml_wlanf.conf
	. $CGI_PATH/../objxml_wan.conf
	. $CGI_PATH/../hgcxml_wan_common.conf
	. $CGI_PATH/../hgcxml_commonf.conf
else
	. $CGI_PATH/../hgcxml.conf
	. $CGI_PATH/../objxml.conf
fi


BROANCONF="$CGI_PATH/../webgui.conf"
QOSCONFPATH="$MISC_CONF_PATH/QoSconf"
QOSCONFPATH_V6="$MISC_CONF_PATH/QoSconfV6"
PONMODE=`$GETCFG ${BROANCONF} PONMODE`

[ -e "$QOSCONFPATH_V6" ] || mkdir $QOSCONFPATH_V6

calIPCv6Key()
{
    #IPģʽ
	variable_IPMode=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPMode; eval variable_IPMode=\$$variable_IPMode
    #IPV6 IP��ַ
	variable_IPv6IPAddress=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6IPAddress; eval variable_IPv6IPAddress=\$$variable_IPv6IPAddress
    #IPV6Ĭ������
	variable_DefaultIPv6Gateway=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_DefaultIPv6Gateway; eval variable_DefaultIPv6Gateway=\$$variable_DefaultIPv6Gateway
    #��ȡǰ׺����Internet��wan���ӿɹ�ѡ�����򲻿ɹ�ѡ
    variable_IPv6PDEn=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6PrefixDelegationEnabled; eval variable_IPv6PDEn=\$$variable_IPv6PDEn
    #ǰ׺�������,ȡֵ��PrefixDelegation��Static��None������ַ��ȡ��ʽΪStaticʱ��ֻ��ѡ��Static
    variable_IPv6PrefixOrigin=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6PrefixOrigin; eval variable_IPv6PrefixOrigin=\$$variable_IPv6PrefixOrigin
    #IPv6��ַ��ȡ��ʽ,ȡֵ��AutoConfigured��DHCPv6(Ĭ��)��Static��None
    variable_IPv6IPAddressOrigin=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6IPAddressOrigin; eval variable_IPv6IPAddressOrigin=\$$variable_IPv6IPAddressOrigin
    #ǰ׺��ַ����ǰ׺�������ΪStaticʱ�����ã�����2000::1/64
    variable_IPv6Prefix=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6Prefix; eval variable_IPv6Prefix=\$$variable_IPv6Prefix
     #IPv6 DNS������
	variable_IPv6DNSServers=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_IPv6DNSServers; eval variable_IPv6DNSServers=\$$variable_IPv6DNSServers
}

calPPPCv6Key()
{
    #IPģʽ
	variable_IPMode=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPMode; eval variable_IPMode=\$$variable_IPMode
    #IPV6 IP��ַ
	variable_IPv6IPAddress=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6IPAddress; eval variable_IPv6IPAddress=\$$variable_IPv6IPAddress
    #IPV6Ĭ������
	variable_DefaultIPv6Gateway=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_DefaultIPv6Gateway; eval variable_DefaultIPv6Gateway=\$$variable_DefaultIPv6Gateway
    #��ȡǰ׺����Internet��wan���ӿɹ�ѡ�����򲻿ɹ�ѡ
    variable_IPv6PDEn=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6PrefixDelegationEnabled; eval variable_IPv6PDEn=\$$variable_IPv6PDEn
    #ǰ׺�������,ȡֵ��PrefixDelegation��Static��None������ַ��ȡ��ʽΪStaticʱ��ֻ��ѡ��Static
    variable_IPv6PrefixOrigin=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6PrefixOrigin; eval variable_IPv6PrefixOrigin=\$$variable_IPv6PrefixOrigin
    #IPv6��ַ��ȡ��ʽ,ȡֵ��AutoConfigured��DHCPv6(Ĭ��)��Static��None
    variable_IPv6IPAddressOrigin=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6IPAddressOrigin; eval variable_IPv6IPAddressOrigin=\$$variable_IPv6IPAddressOrigin
    #ǰ׺��ַ����ǰ׺�������ΪStaticʱ�����ã�����2000::1/64
    variable_IPv6Prefix=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6Prefix; eval variable_IPv6Prefix=\$$variable_IPv6Prefix
    #IPv6 DNS������
	variable_IPv6DNSServers=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_IPv6DNSServers; eval variable_IPv6DNSServers=\$$variable_IPv6DNSServers
}

getv6Key()
{
    GETSTR=`$INTER_WEB get $variable_IPMode \
                                    $variable_IPv6IPAddress \
                                    $variable_DefaultIPv6Gateway \
                                    $variable_IPv6Prefix \
                                    $variable_IPv6DNSServers \
                                    $variable_IPv6PDEn \
                                    $variable_IPv6PrefixOrigin \
                                    $variable_IPv6IPAddressOrigin`
    LINKMODEL_INT=`echo $GETSTR | cut -d '&' -f 1`
    if [ -z "$LINKMODEL_INT" -o "$LINKMODEL_INT" == "NULL" ]; then
        LINKMODEL_INT="1"
    fi

    if [ "$LINKMODEL_INT" == "1" ]; then
        LINKMODEL=ipv4
    fi
    if [ "$LINKMODEL_INT" == "2" ]; then
        LINKMODEL=ipv6
    fi
    if [ "$LINKMODEL_INT" == "3" ]; then
        LINKMODEL="ipv4ipv6"
    fi
    V6ADDRESS_TEMP=`echo $GETSTR | cut -d '&' -f 2`
    V6ADDRESS=`echo "${V6ADDRESS_TEMP}/" | cut -d '/' -f 1`
    WANV6PREFIX=`echo "${V6ADDRESS_TEMP}/" | cut -d '/' -f 2`
    [ "$V6ADDRESS" == "NULL" ] && V6ADDRESS=""
    V6GATEWAY=`echo $GETSTR | cut -d '&' -f 3`
    [ "$V6GATEWAY" == "NULL" ] && V6GATEWAY=""
    V6PREFIX=`echo $GETSTR | cut -d '&' -f 4`
    [ "$V6PREFIX" == "NULL" ] && V6PREFIX=""
    V6DNS=`echo $GETSTR | cut -d '&' -f 5`
    [ "$V6DNS" == "NULL" ] && V6DNS=""
    V6FIRSTDNS=`echo $V6DNS | cut -d ',' -f 1`
	[ "$V6FIRSTDNS" == "NULL" ] && V6FIRSTDNS=""
    V6SECONDDNS=`echo $V6DNS | cut -d ',' -f 2`
	[ "$V6SECONDDNS" == "NULL" ] && V6SECONDDNS=""
    IPV6PDEN=`echo $GETSTR | cut -d '&' -f 6`
    IPV6PREFIXORIGIN=`echo $GETSTR | cut -d '&' -f 7`
    IPV6IPADDRESSORIGIN=`echo $GETSTR | cut -d '&' -f 8`
}

IPV6WANCONF ()
{
L_VlanNum=IGD_WAND_1_WANCD_${CHOOSE}_X_FIB_COM_VlanNum
eval L_VlanNum=\$$L_VlanNum
}

deleteQosV6()
{
		sed '/^$/d' $QOSCONFPATH_V6/WanQoS.conf > $QOSCONFPATH_V6/WanQoS.conf.tmp 2> /dev/null
		grep -v "L_$LINKNAME" $QOSCONFPATH_V6/WanQoS.conf.tmp > $QOSCONFPATH_V6/WanQoS.conf 2> /dev/null
		rm $QOSCONFPATH_V6/L_${LINKNAME}* 2> /dev/null
		rm $QOSCONFPATH_V6/mangle-$1[1-5] 2> /dev/null
		rm $QOSCONFPATH_V6/WanQoS.conf.tmp 2> /dev/null
}
deleteQosV4()
{
		sed '/^$/d' $QOSCONFPATH/WanQoS.conf > $QOSCONFPATH/WanQoS.conf.tmp 2> /dev/null
		grep -v "L_$LINKNAME" $QOSCONFPATH/WanQoS.conf.tmp > $QOSCONFPATH/WanQoS.conf 2> /dev/null
		rm $QOSCONFPATH/L_${LINKNAME}* 2> /dev/null
		rm $QOSCONFPATH/mangle-$1[1-5] 2> /dev/null
		rm $QOSCONFPATH/WanQoS.conf.tmp 2> /dev/null
}

calculateCommonKey(){
	if [ "$PONMODE" == "GPON" ];then
		G_VLANIDMark=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANGLC_VLANIDMark; eval G_VLANIDMark=\$$G_VLANIDMark
		G_8021pMark=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANGLC_802_1pMark; eval G_8021pMark=\$$G_8021pMark
		G_Mode=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANGLC_Mode; eval G_Mode=\$$G_Mode
	else
		G_VLANIDMark=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANELC_VLANIDMark; eval G_VLANIDMark=\$$G_VLANIDMark
		G_8021pMark=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANELC_802_1pMark; eval G_8021pMark=\$$G_8021pMark
		G_Mode=IGD_WAND_1_WANCD_${CHOOSE1}_XCTCOMWANELC_Mode; eval G_Mode=\$$G_Mode
    fi
	IPC_Enable=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_Enable; eval IPC_Enable=\$$IPC_Enable
	PPPC_Enable=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_Enable; eval PPPC_Enable=\$$PPPC_Enable
}

calculateStaticKey(){
    IPC_ExternalIPAddress=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_ExternalIPAddress
	IPC_SubnetMask=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_SubnetMask
	IPC_DefaultGateway=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_DefaultGateway
	IPC_DNSServers=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_DNSServers
	eval IPC_ExternalIPAddress=\$$IPC_ExternalIPAddress
	eval IPC_SubnetMask=\$$IPC_SubnetMask
	eval IPC_DefaultGateway=\$$IPC_DefaultGateway
	eval IPC_DNSServers=\$$IPC_DNSServers
}

calculateIPCKey(){
    delobj_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_1
	delobj_index1=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_1
	addobj_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC
	IPC_ConnectionType=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_ConnectionType
	IPC_NATEnabled=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_NATEnabled
	IPC_ServiceList=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_ServiceList
	IPC_AddressingType=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_AddressingType
	IPC_LanInterface=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_LanInterface
	IPC_QOS=IGD_WAND_1_WANCD_${CHOOSE1}_X_FIB_COM_QosEnable
	IPC_MTU=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_MaxMTUSize
	IPC_DslitEnable=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_Dslite_Enable
	IPC_AftrEnable=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_AftrMode
	IPC_Aftr=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_CT_COM_Aftr
	IPC_SessionIndex=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_${CHOOSE2}_X_FIB_COM_SessionIndex
	eval delobj_index=\$$delobj_index
	eval delobj_index1=\$$delobj_index1
	eval addobj_index=\$$addobj_index
	eval IPC_ConnectionType=\$$IPC_ConnectionType
	eval IPC_NATEnabled=\$$IPC_NATEnabled
	eval IPC_ServiceList=\$$IPC_ServiceList
	eval IPC_AddressingType=\$$IPC_AddressingType
	eval IPC_LanInterface=\$$IPC_LanInterface
	eval IPC_QOS=\$$IPC_QOS
	eval IPC_MTU=\$$IPC_MTU
	eval IPC_DslitEnable=\$$IPC_DslitEnable
	eval IPC_AftrEnable=\$$IPC_AftrEnable
	eval IPC_Aftr=\$$IPC_Aftr
	eval IPC_SessionIndex=\$$IPC_SessionIndex
}

calculatePPPCKey(){
    delobj_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_1
	delobj_index1=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_1
	addobj_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC
	PPPC_ServiceList=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_ServiceList
	PPPC_ConnectionType=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_ConnectionType
	PPPC_LanInterface=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_LanInterface
	PPPC_TransportType=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_TransportType
	PPPC_QOS=IGD_WAND_1_WANCD_${CHOOSE1}_X_FIB_COM_QosEnable
	PPPC_MTU=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_CurrentMRUSize
	PPPC_DslitEnable=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_Dslite_Enable
	PPPC_AftrEnable=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_AftrMode
	PPPC_Aftr=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_Aftr
	PPPC_SessionIndex=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_FIB_COM_SessionIndex
	eval delobj_index=\$$delobj_index
	eval delobj_index1=\$$delobj_index1
	eval addobj_index=\$$addobj_index
	eval PPPC_ServiceList=\$$PPPC_ServiceList
	eval PPPC_ConnectionType=\$$PPPC_ConnectionType
	eval PPPC_LanInterface=\$$PPPC_LanInterface
	eval PPPC_TransportType=\$$PPPC_TransportType
	eval PPPC_QOS=\$$PPPC_QOS
	eval PPPC_MTU=\$$PPPC_MTU
	eval PPPC_DslitEnable=\$$PPPC_DslitEnable
	eval PPPC_AftrEnable=\$$PPPC_AftrEnable
	eval PPPC_Aftr=\$$PPPC_Aftr
	eval PPPC_SessionIndex=\$$PPPC_SessionIndex
}

calculateRoutePppoeKey(){
    PPPC_NATEnabled=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_NATEnabled
    PPPC_ProxyEnable=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_ProxyEnable
	PPPC_MAXUser=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_X_CT_COM_MAXUser
	PPPC_Username=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_Username
	PPPC_Password=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_Password
	PPPC_ServiceName=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_PPPoEServiceName
	PPPC_ConnectionTrigger=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_ConnectionTrigger
    PPPC_IdleDisconnectTime=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_${CHOOSE2}_IdleDisconnectTime
    eval PPPC_IdleDisconnectTime=\$$PPPC_IdleDisconnectTime
	eval PPPC_NATEnabled=\$$PPPC_NATEnabled
	eval PPPC_ProxyEnable=\$$PPPC_ProxyEnable
	eval PPPC_MAXUser=\$$PPPC_MAXUser
	eval PPPC_Username=\$$PPPC_Username
	eval PPPC_Password=\$$PPPC_Password
	eval PPPC_ServiceName=\$$PPPC_ServiceName
	eval PPPC_ConnectionTrigger=\$$PPPC_ConnectionTrigger
}

ipmode_dhcp_v6par()
{
	IPV6WANCONF
	calIPCv6Key
	calculateCommonKey
	calculateIPCKey
    [ -n "$LINKMODEL_INT" ] && RETURNSTR=`$INTER_WEB set $variable_IPMode  $LINKMODEL_INT`
    if [ "$LINKMODEL_INT"  != "1"  ];then
		if [ "$IPv6PDEn_mode1" == "1" ]; then
			RETURNSTR=`$INTER_WEB set $variable_IPv6PDEn $GAINPREFIX`
		fi
		RETURNSTR=`$INTER_WEB set $variable_IPv6IPAddressOrigin $GAINADDRESS`	    
		if [ "$GAINPREFIX" == "1" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6PrefixOrigin "$PREFIXORIGIN"`
            [ "$PREFIXORIGIN" == "Static" ] && RETURNSTR=`$INTER_WEB set $variable_IPv6Prefix "$IPV6PREFIX"`
        fi
         [ "x$DslitEnable" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_DslitEnable $DslitEnable`
         [ "x$AftrEnable" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_AftrEnable $AftrEnable`
         [ "x$Aftr" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_Aftr $Aftr` 
		
		if [ "$ENVLANMUX" == "0" ]; then
		    RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.'|'$GAINADDRESS$GAINPREFIX`
	    else
		    RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.$VLANMUXID'|'$GAINADDRESS$GAINPREFIX`
	    fi       
    fi
}

ipmode_static_v6par()
{
	 calIPCv6Key
	 calculateIPCKey
    [ -n "$LINKMODEL_INT" ] && RETURNSTR=`$INTER_WEB set $variable_IPMode $LINKMODEL_INT`
    if [ "$LINKMODEL_INT"  != "1"  ];then
      	RETURNSTR=`$INTER_WEB set $variable_DefaultIPv6Gateway $V6GATEWAY`
		
		RETURNSTR=`$INTER_WEB set $variable_IPv6IPAddressOrigin "$GAINADDRESS"`
		 
		RETURNSTR=`$INTER_WEB set $variable_IPv6IPAddress "$V6ADDRESS/${WANV6PREFIX}"` 								  
        if [ "$V6FIRSTDNS" == "" -a "$V6SECONDDNS" == "" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6DNSServers ""`
        elif [ "$V6FIRSTDNS" != "" -a "$V6SECONDDNS" == "" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6DNSServers "$V6FIRSTDNS"`
        elif [ "$V6FIRSTDNS" == "" -a "$V6SECONDDNS" != "" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6DNSServers ",${V6SECONDDNS}"`
        elif [ "$V6FIRSTDNS" != "" -a "$V6SECONDDNS" != "" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6DNSServers "${V6FIRSTDNS},${V6SECONDDNS}"`
        fi
		if [ "$IPv6PDEn_mode1" == "1" ]; then
			RETURNSTR=`$INTER_WEB set $variable_IPv6PDEn "$GAINPREFIX"`
		fi
        if [ "$GAINPREFIX" == "1" ]; then
            RETURNSTR=`$INTER_WEB set $variable_IPv6PrefixOrigin "$PREFIXORIGIN"`
            [ "$PREFIXORIGIN" == "Static" ] && RETURNSTR=`$INTER_WEB set $variable_IPv6Prefix "$IPV6PREFIX"`
        fi
         [ "x$DslitEnable" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_DslitEnable $DslitEnable`
        [ "x$AftrEnable" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_AftrEnable $AftrEnable`
        [ "x$Aftr" != "x" ] && RETURN_STR=`$INTER_WEB set $IPC_Aftr $Aftr` 
		
    fi  
}

ipmode_pppoe_v6par()
{
	IPV6WANCONF
	calPPPCv6Key
	calculateCommonKey
	calculatePPPCKey
    [ -n "$LINKMODEL_INT" ] && RETURNSTR=`$INTER_WEB set $variable_IPMode $LINKMODEL_INT`
    if [ "$LINKMODEL_INT"  != "1"  ];then
        if [ "$MODEL" == "Routed" ] ; then
			if [ "$IPv6PDEn_mode1" == "1" ]; then
				RETURNSTR=`$INTER_WEB set $variable_IPv6PDEn $GAINPREFIX`
			fi
			RETURNSTR=`$INTER_WEB set $variable_IPv6IPAddressOrigin $GAINADDRESS`
			if [ "$GAINPREFIX" == "1" ]; then
                RETURNSTR=`/usr/bin/inter_web set $variable_IPv6PrefixOrigin "$PREFIXORIGIN"`
                [ "$PREFIXORIGIN" == "Static" ] && RETURNSTR=`/usr/bin/inter_web set $variable_IPv6Prefix "$IPV6PREFIX"`
            fi
            [ "x$DslitEnable" != "x" ] && RETURN_STR=`/usr/bin/inter_web set $PPPC_DslitEnable $DslitEnable`
            [ "x$AftrEnable" != "x" ] && RETURN_STR=`/usr/bin/inter_web set $PPPC_AftrEnable $AftrEnable`
            [ "x$Aftr" != "x" ] && RETURN_STR=`/usr/bin/inter_web set $PPPC_Aftr $Aftr`
			
			if [ "$ENVLANMUX" == "0" ]; then
				RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.'|'$GAINADDRESS$GAINPREFIX`
			else
				RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.$VLANMUXID'|'$GAINADDRESS$GAINPREFIX`
			fi
		else
        	RETURNSTR=`$INTER_WEB set $variable_IPv6PDEn 0`
            RETURNSTR=`$INTER_WEB set $variable_DefaultIPv6Gateway "$V6GATEWAY"`
            RETURNSTR=`$INTER_WEB set $variable_IPv6IPAddress "$V6ADDRESS/${WANV6PREFIX}"`
            RETURNSTR=`$INTER_WEB set $variable_IPv6DNSServers ""`
			
			if [ "$ENVLANMUX" == "0" ]; then
				RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.'|'00`
			else
				RETURNSTR=`$INTER_WEB set $L_VlanNum ${WANINTERFACE}.$VLANMUXID'|'00`
			fi
		fi
    fi     
}

ipmodel_dhcp()
{
    calculateIPCKey
	index=`$INTER_WEB get $IPC_SessionIndex | cut -d '&' -f 1`
	RETURN_STR=`$MOREMGT delobj $delobj_index`
	RETURN_STR=`$MOREMGT delobj $delobj_index1`
	RETURN_STR=`$MOREMGT addobj $addobj_index`
	RETURN_STR=`$INTER_WEB set $IPC_SessionIndex $index`
	SAVESTR="${IPC_ServiceList} ${SERVICEMODE}"
	SAVESTR="${SAVESTR} ${IPC_LanInterface} ${BINDLANLST}"
	RETURN_STR=`$INTER_WEB set $SAVESTR`
	RETURN_STR=`$INTER_WEB set $IPC_ConnectionType IP_${MODEL} \
	                        $G_VLANIDMark $VLANMUXID \
							$G_8021pMark $D8021 \
							$IPC_AddressingType $IPMODEL \
							$IPC_NATEnabled $ENBLNAT \
							$IPC_MTU $MTU \
							$IPC_DslitEnable $DslitEnable \
							$IPC_AftrEnable $AftrEnable \
							$IPC_Aftr $Aftr \
							$G_Mode $ENVLANMUX`
     						
	ipmode_dhcp_v6par $CHOOSE1 $CHOOSE2
	RETURN_STR=`$INTER_WEB set $IPC_Enable 1`
}

ipmodel_static()
{
    calculateIPCKey
	calculateStaticKey
	index=`$INTER_WEB get $IPC_SessionIndex | cut -d '&' -f 1`
	RETURN_STR=`$MOREMGT delobj $delobj_index`
	RETURN_STR=`$MOREMGT delobj $delobj_index1`
	RETURN_STR=`$MOREMGT addobj $addobj_index`
	RETURN_STR=`$INTER_WEB set $IPC_SessionIndex $index`
	SAVESTR="${IPC_ServiceList} ${SERVICEMODE}"
	SAVESTR="${SAVESTR} ${IPC_LanInterface} ${BINDLANLST}"
	RETURN_STR=`$INTER_WEB set $SAVESTR`
	[ "$DNS_XML" == "" ] && DNS_XML="NULL" 
	RETURN_STR=`$INTER_WEB set $IPC_ConnectionType IP_${MODEL} \
	                        $G_VLANIDMark $VLANMUXID \
							$G_8021pMark $D8021 \
							$IPC_AddressingType $IPMODEL \
							$IPC_NATEnabled $ENBLNAT \
							$IPC_MTU $MTU \
							$IPC_DslitEnable $DslitEnable \
							$IPC_AftrEnable $AftrEnable \
							$IPC_Aftr $Aftr \
							$IPC_ExternalIPAddress $WANIPADDRESS \
							$IPC_SubnetMask $WANSUBNETMASK \
							$IPC_DefaultGateway $DEFAULTGATEWAY \
							$IPC_DNSServers "$DNS_XML" \
							$G_Mode $ENVLANMUX`
	ipmode_static_v6par $CHOOSE1 $CHOOSE2
	RETURN_STR=`$INTER_WEB set $IPC_Enable 1 `
}

ipmodel_pppoe()
{
    calculatePPPCKey
	index=`$INTER_WEB get $PPPC_SessionIndex | cut -d '&' -f 1`
	RETURN_STR=`$MOREMGT delobj $delobj_index`
	RETURN_STR=`$MOREMGT delobj $delobj_index1`
	RETURN_STR=`$MOREMGT addobj $addobj_index`
	RETURN_STR=`$INTER_WEB set $PPPC_SessionIndex $index`
    RETURN_STR=`$INTER_WEB set $PPPC_ServiceList $SERVICEMODE`
	RETURN_STR=`$INTER_WEB set $PPPC_MTU $MTU`
	RETURN_STR=`$INTER_WEB set $PPPC_DslitEnable $DslitEnable`
	RETURN_STR=`$INTER_WEB set $PPPC_AftrEnable $AftrEnable`
	RETURN_STR=`$INTER_WEB set $PPPC_Aftr $Aftr`
	   
	RETURN_STR=`$INTER_WEB set $PPPC_LanInterface $BINDLANLST`
	if [ "x$PPPTOBRIDGE" != "x" ]; then
		[ "x$PPPTOBRIDGE" == "x1" ] && PPPTOBRIDGE="Enabled" || PPPTOBRIDGE="Disabled"
		RETURN_STR=`$INTER_WEB set $PPPC_TransportType $PPPTOBRIDGE`
	fi
	if [ "$MODEL" == "Routed" ] || [ "$SERVICEMODE" == "TR069,VOIP,INTERNET" ] || [ "$SERVICEMODE" == "TR069,INTERNET" ] || [ "$SERVICEMODE" == "VOIP,INTERNET" ]; then
	    calculateRoutePppoeKey
		if [ "$MODEL" == "Routed" ]; then
			RETURN_STR=`$INTER_WEB set $PPPC_ConnectionType IP_${MODEL}`
		fi
		RETURN_STR=`$INTER_WEB set $G_VLANIDMark $VLANMUXID \
		                    $G_8021pMark $D8021 \
		                    $PPPC_NATEnabled $ENBLNAT \
							$PPPC_Username $PPPUSERNAME \
							$PPPC_Password $PPPPASSWORD \
							$PPPC_ConnectionTrigger $DIAL \
							$G_Mode $ENVLANMUX`
		[ "$DIAL" == "OnDemand" -a "x$DIALTIME" != "x" ] && RETURN_STR=`$INTER_WEB set $PPPC_IdleDisconnectTime $DIALTIME`
		ipmode_pppoe_v6par $CHOOSE1 $CHOOSE2
		[ -n "$PPPSERVERNAME" ] && RETURN_STR=$($INTER_WEB set $PPPC_ServiceName $PPPSERVERNAME)
		RETURN_STR=`$INTER_WEB set $PPPC_Enable 1 `

	else
		RETURN_STR=`$INTER_WEB set $PPPC_ConnectionType PPPoE_${MODEL}`
		RETURN_STR=`$INTER_WEB set $G_VLANIDMark $VLANMUXID \
		                $G_8021pMark $D8021 \
						$G_Mode $ENVLANMUX`
		ipmode_pppoe_v6par $CHOOSE1 $CHOOSE2
		RETURN_STR=`$INTER_WEB set $PPPC_Enable 1 `							
	fi
}

modifyIgmpConfig(){
	ENABLEMLD_CONNETNAME=`$INTER_WEB get $IGD_S_XCTCOMIPTV_X_FIB_COM_IGMPProxy | cut -d '&' -f 1`
	if [ "$ENABLEMLD_CONNETNAME" == "$LINKNAME" ]; then
	    #ENABLEMLD_CONNETNAME=`echo "$ENABLEMLD_CONNETNAME" | cut -d '_' -f 1`
	    #if echo "$ENABLEMLD_CONNETNAME" | grep -q "^$CHOOSE"; then		
	        RETURN_STR=`$INTER_WEB set $IGD_S_XCTCOMIPTV_X_FIB_COM_IGMPProxy ""`
		    RETURN_STR=`$INTER_WEB set $IGD_S_XCTCOMIPTV_ProxyEnable 0`
	    #fi
	fi
}

modifyMldConfig(){
	ENABLEMLD_CONNETNAME=`$INTER_WEB get $IGD_S_XCTCOMIPTV_X_FIB_COM_MldProxyName | cut -d '&' -f 1`
	if [ "$ENABLEMLD_CONNETNAME" == "$LINKNAME" ]; then
	    #ENABLEMLD_CONNETNAME=`echo "$ENABLEMLD_CONNETNAME" | cut -d '_' -f 1`
	    #if echo "$ENABLEMLD_CONNETNAME" | grep -q "^$CHOOSE"; then
	        RETURN_STR=`$INTER_WEB set $IGD_S_XCTCOMIPTV_X_FIB_COM_MldProxyName ""`
		    RETURN_STR=`$INTER_WEB set $IGD_S_XCTCOMIPTV_X_FIB_COM_MldProxyEnable 0`
		#fi
	fi
}

readwaninterface()
{
       WANINTERFACE="pon0"
}


getbroadbund()
{
wirelessenable=`$GETCFG ${BROANCONF} wireless_enable`
Portnumber=`$GETCFG ${BROANCONF} Port_number`
GETSTR=`$INTER_WEB get $IGD_LAND_1_WLANC_1_Enable \
				$IGD_LAND_1_WLANC_2_Enable \
				$IGD_LAND_1_WLANC_3_Enable \
				$IGD_LAND_1_WLANC_4_Enable`
for paramIndex in 1 2 3 4
do
	val=`echo "$GETSTR" | cut -d '&' -f ${paramIndex}`
	if [ "$val" == "NULL" ];then
		val=""
	fi
	case $paramIndex
		in
		"1")
 		WLTH1=$val
 		;;
 		"2")
 		WLTH2=$val
		[ "$WLTH2" == "1" ] && WLTH2_D=0 || WLTH2_D=1 
 		;;
 		"3")
 		WLTH3=$val
		[ "$WLTH3" == "1" ] && WLTH3_D=0 || WLTH3_D=1
 		;;
 		"4")
 		WLTH4=$val
		[ "$WLTH4" == "1" ] && WLTH4_D=0 || WLTH4_D=1
 		;;
 		*)
 		break
 		;;
 	esac
done

show_Index=`$GETCFG ${BROANCONF} show_Index`
CHOOSE1=
CHOOSE2=
MODE_index=0

for index_1 in 1 2 3 4 5 6 7 8; do
	for index_2 in 1 2; do
		IPC_Enable_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Enable
		eval IPC_Enable_index=\$$IPC_Enable_index
		FLAG=`$INTER_WEB get $IPC_Enable_index | cut -d '&' -f 1`
		if [ "$FLAG" == "1" ]; then
			IPC_Name_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Name
			eval IPC_Name_index=\$$IPC_Name_index
			CONNECTNAME_temp=`$INTER_WEB get $IPC_Name_index | cut -d '&' -f 1`
		else
			continue
		fi
		CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`		
		CHOOSE=`echo "$CONNECTNAME_temp" | cut -d '_' -f 1`
		if [ "$CHOOSE" == "$show_Index" ]; then
			CHOOSE1=$index_1
			CHOOSE2=$index_2
			MODE_index=1
		fi		
		eval CONNECTNAMEIPC${index_1}${index_2}=$CONNECTNAME_temp
	done
done

for index_3 in 1 2 3 4 5 6 7 8; do
	for index_4 in 1 2; do
		PPPC_Enable_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Enable		
		eval PPPC_Enable_index=\$$PPPC_Enable_index
		FLAG=`$INTER_WEB get $PPPC_Enable_index | cut -d '&' -f 1`
		if [ "$FLAG" == "1" ]; then
			PPPC_Name_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Name
			eval PPPC_Name_index=\$$PPPC_Name_index
			CONNECTNAME_temp=`$INTER_WEB get $PPPC_Name_index | cut -d '&' -f 1`
		else
			continue
		fi
		CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
		CHOOSE=`echo "$CONNECTNAME_temp" | cut -d '_' -f 1`
		if [ "$CHOOSE" == "$show_Index" ]; then
			CHOOSE1=$index_3
			CHOOSE2=$index_4
			MODE_index=2
		fi	
		eval CONNECTNAMEPPPC${index_3}${index_4}=$CONNECTNAME_temp	
	done
done


LINKNAME=`$GETCFG ${BROANCONF} linkname`

if echo "$CHOOSE1" | grep -q '[1-8]'; then	
    calculateCommonKey
    GETSTR=`$INTER_WEB get $G_VLANIDMark \
	                               $G_8021pMark \
								   $IPC_Enable \
								   $PPPC_Enable \
								   $G_Mode`
	
	VLANMUXID=`echo "$GETSTR" | cut -d '&' -f 1`
	D8021=`echo "$GETSTR" | cut -d '&' -f 2`
	IPCENABLE=`echo "$GETSTR" | cut -d '&' -f 3`
	PPPENABLE=`echo "$GETSTR" | cut -d '&' -f 4`
	ENVLANMUX=`echo "$GETSTR" | cut -d '&' -f 5`
	[ "$D8021" == "-1" ] && D8021=0
	[ "$VLANMUXID" == "-1" ] && VLANMUXID=0
    [ "$ENVLANMUX" == "0" ] && { VLANMUXID=0 
	    D8021=0 
	} || { ENVLANMUX=1
	}
	if [ "$MODE_index" == "1" ]; then
	    calculateIPCKey
	    GETSTR=`$INTER_WEB get $IPC_ConnectionType \
	                               $IPC_NATEnabled \
								   $IPC_ServiceList \
								   $IPC_AddressingType \
								   $IPC_LanInterface\
								   $IPC_MTU \
								   $IPC_DslitEnable \
								   $IPC_AftrEnable \
								   $IPC_Aftr `
		MODEL=`echo "$GETSTR" | cut -d '&' -f 1`
		ENBLNAT=`echo "$GETSTR" | cut -d '&' -f 2`
		SERVICEMODE=`echo "$GETSTR" | cut -d '&' -f 3`
		IPMODEL=`echo "$GETSTR" | cut -d '&' -f 4`
		BINDLANLST=`echo "$GETSTR" | cut -d '&' -f 5`
		MTU=`echo "$GETSTR" | cut -d '&' -f 6`
		DslitEnable=`echo "$GETSTR" | cut -d '&' -f 7`
		AftrEnable=`echo "$GETSTR" | cut -d '&' -f 8`
		Aftr=`echo "$GETSTR" | cut -d '&' -f 9`	
       [ "$Aftr" == "NULL" ] && Aftr="" 		
		if [ "$IPMODEL" == "Static" ]; then
		    calculateStaticKey
			GETSTR=`$INTER_WEB get $IPC_ExternalIPAddress \
	                               $IPC_SubnetMask \
								   $IPC_DefaultGateway \
								   $IPC_DNSServers`
		    WANIPADDRESS=`echo "$GETSTR" | cut -d '&' -f 1`
			WANSUBNETMASK=`echo "$GETSTR" | cut -d '&' -f 2`
			DEFAULTGATEWAY=`echo "$GETSTR" | cut -d '&' -f 3`
			DNS=`echo "$GETSTR" | cut -d '&' -f 4 `
			[ "$DNS" == "NULL" ] && DNS="" 	
			DNSPRIMARY=`echo "$DNS," | cut -d ',' -f 1`
			[ "$DNSPRIMARY" == "NULL" ] && DNSPRIMARY="" 	
		    DNSSECONDARY=`echo "$DNS," | cut -d ',' -f 2`
			[ "$DNSSECONDARY" == "NULL" ] && DNSSECONDARY="" 	
		fi
		 calIPCv6Key ${CHOOSE1} ${CHOOSE2}	 
	else    
	    calculatePPPCKey
		calculateRoutePppoeKey
	    GETSTR=`$INTER_WEB get $PPPC_ConnectionType \
	                               $PPPC_NATEnabled \
								   $PPPC_ServiceList \
								   $PPPC_LanInterface \
								   $PPPC_ProxyEnable \
								   $PPPC_MAXUser \
								   $PPPC_Username \
								   $PPPC_Password \
								   $PPPC_TransportType \
								   $PPPC_ServiceName \
								   $PPPC_ConnectionTrigger\
								   $PPPC_MTU \
								   $PPPC_IdleDisconnectTime `
								  
		MODEL=`echo "$GETSTR" | cut -d '&' -f 1`
		
		ENBLNAT=`echo "$GETSTR" | cut -d '&' -f 2`
		SERVICEMODE=`echo "$GETSTR" | cut -d '&' -f 3`
		IPMODEL="PPPoE"
		BINDLANLST=`echo "$GETSTR" | cut -d '&' -f 4`
		ENBLPPPRTPROXY=`echo "$GETSTR" | cut -d '&' -f 5`
		PPPPROXYMAXUSER=`echo "$GETSTR" | cut -d '&' -f 6`
		PPPUSERNAME=`echo "$GETSTR" | cut -d '&' -f 7`
		PPPPASSWORD=`echo "$GETSTR" | cut -d '&' -f 8`
		PPPTOBRIDGE=`echo "$GETSTR" | cut -d '&' -f 9`
		PPPSERVERNAME=`echo "$GETSTR" | cut -d '&' -f 10`
		DIAL=`echo "$GETSTR" | cut -d '&' -f 11`
		MTU=`echo "$GETSTR" | cut -d '&' -f 12`
		DIALTIME=`echo "$GETSTR" | cut -d '&' -f 13`
		
		GETSTR=`$INTER_WEB attri $PPPC_Username \
					$PPPC_Password`
		PPPUNAMESUBCRIBER=`echo "$GETSTR" | cut -d '&' -f 1`
		PPPPWDSUBCRIBER=`echo "$GETSTR" | cut -d '&' -f 2`
		
            GETSTR=`$INTER_WEB get $PPPC_DslitEnable \
                                       $PPPC_AftrEnable \
                                       $PPPC_Aftr`
            DslitEnable=`echo "$GETSTR" | cut -d '&' -f 1`
		    AftrEnable=`echo "$GETSTR" | cut -d '&' -f 2`
		    Aftr=`echo "$GETSTR" | cut -d '&' -f 3`
            [ "$Aftr" == "NULL" ] && Aftr=""
       
		calPPPCv6Key ${CHOOSE1} ${CHOOSE2}
	fi
	VLANSUBCRIBER=`$INTER_WEB attri $G_VLANIDMark | cut -d '&' -f 1`
	getv6Key
fi


paramIndex="1"
CGIParam=`echo "$BINDLANLST," | cut -d ',' -f $paramIndex`
while [ "$CGIParam" != "" ]
	do
		val1=`echo "$CGIParam" | cut -d '.' -f 2`
		val2=`echo "$CGIParam" | cut -d '.' -f 3`
		if [ "$val1" == "eth" ]; then
		case $val2
		in
			"1")
			EP1=1
			;;
			"2")
			EP2=1
			;;
			"3")
			EP3=1
			;;
			"4")
			EP4=1
			;;
			*)
			break
			;;
		esac
		elif [ "$val1" == "wla" ]; then
		case $val2
		in
			"1")
			WP1=1
			;;
			"2")
			WP2=1
			;;
			"3")
			WP3=1
			;;
			"4")
			WP4=1
			;;
			*)
			break
			;;
		esac
		fi
		paramIndex=$((paramIndex+1))
		CGIParam=`echo "$BINDLANLST," | cut -d ',' -f $paramIndex`
	done

[ "$PPPTOBRIDGE" == "Enabled" ] && PPPTOBRIDGE="1" || PPPTOBRIDGE="0"

[ "$ENVLANMUX" -ne "0" ] && ENVLANMUX=1

IPTVMODEL=`$INTER_WEB get $IGD_DI_XCTCOMIPPV_Mode | cut -d '&' -f 1`


echo "
{\"RETURN\":
  {\"success\": true},
 \"BROADBUND\":
  {\"broadbund_connectnameipc11\":\"$CONNECTNAMEIPC11\",
   \"broadbund_connectnameipc12\":\"$CONNECTNAMEIPC12\",
   \"broadbund_connectnameipc21\":\"$CONNECTNAMEIPC21\",
   \"broadbund_connectnameipc22\":\"$CONNECTNAMEIPC22\",
   \"broadbund_connectnameipc31\":\"$CONNECTNAMEIPC31\",
   \"broadbund_connectnameipc32\":\"$CONNECTNAMEIPC32\",
   \"broadbund_connectnameipc41\":\"$CONNECTNAMEIPC41\",
   \"broadbund_connectnameipc42\":\"$CONNECTNAMEIPC42\",
   \"broadbund_connectnameipc51\":\"$CONNECTNAMEIPC51\",
   \"broadbund_connectnameipc52\":\"$CONNECTNAMEIPC52\",
   \"broadbund_connectnameipc61\":\"$CONNECTNAMEIPC61\",
   \"broadbund_connectnameipc62\":\"$CONNECTNAMEIPC62\",
   \"broadbund_connectnameipc71\":\"$CONNECTNAMEIPC71\",
   \"broadbund_connectnameipc72\":\"$CONNECTNAMEIPC72\",
   \"broadbund_connectnameipc81\":\"$CONNECTNAMEIPC81\",
   \"broadbund_connectnameipc82\":\"$CONNECTNAMEIPC82\",
   \"broadbund_connectnameppc11\":\"$CONNECTNAMEPPPC11\",
   \"broadbund_connectnameppc12\":\"$CONNECTNAMEPPPC12\",
   \"broadbund_connectnameppc21\":\"$CONNECTNAMEPPPC21\",
   \"broadbund_connectnameppc22\":\"$CONNECTNAMEPPPC22\",
   \"broadbund_connectnameppc31\":\"$CONNECTNAMEPPPC31\",
   \"broadbund_connectnameppc32\":\"$CONNECTNAMEPPPC32\",
   \"broadbund_connectnameppc41\":\"$CONNECTNAMEPPPC41\",
   \"broadbund_connectnameppc42\":\"$CONNECTNAMEPPPC42\",
   \"broadbund_connectnameppc51\":\"$CONNECTNAMEPPPC51\",
   \"broadbund_connectnameppc52\":\"$CONNECTNAMEPPPC52\",
   \"broadbund_connectnameppc61\":\"$CONNECTNAMEPPPC61\",
   \"broadbund_connectnameppc62\":\"$CONNECTNAMEPPPC62\",
   \"broadbund_connectnameppc71\":\"$CONNECTNAMEPPPC71\",
   \"broadbund_connectnameppc72\":\"$CONNECTNAMEPPPC72\",
   \"broadbund_connectnameppc81\":\"$CONNECTNAMEPPPC81\",
   \"broadbund_connectnameppc82\":\"$CONNECTNAMEPPPC82\",
   \"broadbund_linkname\":\"$LINKNAME\",
   \"broadbund_servicemode\":\"$SERVICEMODE\",
   \"broadbund_model\":\"$MODEL\",
   \"broadbund_ipmodel\":\"$IPMODEL\",
   \"broadbund_iptvmodel\":\"$IPTVMODEL\",
   \"broadbund_ppptobridge\":\"$PPPTOBRIDGE\",
   \"broadbund_enblnat\":\"$ENBLNAT\",
   \"broadbund_envlanmux\":\"$ENVLANMUX\",
   \"broadbund_vlanmuxid\":\"$VLANMUXID\",
   \"broadbund_d8021\":\"$D8021\",
   \"broadbund_pppusername\":\"$PPPUSERNAME\",
   \"broadbund_ppppassword\":\"$PPPPASSWORD\",
   \"broadbund_pppservername\":\"$PPPSERVERNAME\",
   \"broadbund_dial\":\"$DIAL\",
   \"broadbund_wanipaddress\":\"$WANIPADDRESS\",
   \"broadbund_wansubnetmask\":\"$WANSUBNETMASK\",
   \"broadbund_defaultgateway\":\"$DEFAULTGATEWAY\",
   \"broadbund_dnsprimary\":\"$DNSPRIMARY\",
   \"broadbund_dnssecondary\":\"$DNSSECONDARY\",
   \"broadbund_PPPUNAMESUBCRIBER\":\"$PPPUNAMESUBCRIBER\",
   \"broadbund_PPPPWDSUBCRIBER\":\"$PPPPWDSUBCRIBER\", 
   \"broadbund_VLANSUBCRIBER\":\"$VLANSUBCRIBER\",   
   \"broadbund_wlth1\":\"$WLTH1\",
   \"broadbund_wlth2\":\"$WLTH2\",
   \"broadbund_wlth3\":\"$WLTH3\",
   \"broadbund_wlth4\":\"$WLTH4\",
   \"broadbund_ep1\":\"$EP1\",
   \"broadbund_ep2\":\"$EP2\",
   \"broadbund_ep3\":\"$EP3\",
   \"broadbund_ep4\":\"$EP4\",
   \"broadbund_wp1\":\"$WP1\",
   \"broadbund_wp2\":\"$WP2\",
   \"broadbund_wp3\":\"$WP3\",
   \"broadbund_wp4\":\"$WP4\",
   \"broadbund_mtu\":\"$MTU\", 
   \"broadbund_linkmodel\":\"$LINKMODEL\",
   \"broadbund_v6address\":\"$V6ADDRESS\",
   \"broadbund_wanv6prefix\":\"$WANV6PREFIX\",
   \"broadbund_v6gateway\":\"$V6GATEWAY\",
   \"broadbund_gainprefix\":\"$IPV6PDEN\",
   \"broadbund_PrefixOrigin\":\"$IPV6PREFIXORIGIN\",
   \"broadbund_gainaddress\":\"$IPV6IPADDRESSORIGIN\",
   \"broadbund_v6prefix\":\"$V6PREFIX\",
   \"broadbund_v6firstdns\":\"$V6FIRSTDNS\",
   \"broadbund_v6seconddns\":\"$V6SECONDDNS\",
   \"broadbund_v6dns\":\"$V6DNS\",
   \"broadbund_DslitEnable\":\"$DslitEnable\",
   \"broadbund_AftrEnable\":\"$AftrEnable\",
   \"broadbund_Aftr\":\"$Aftr\",
   \"broadbund_DIALTIME\":\"$DIALTIME\",
   \"broadbund_area\":\"$area\",
   \"wirelessenable\":\"$wirelessenable\",
   \"Portnumber\":\"$Portnumber\"}
}"

}


setbroadbund()
{
		# QUERY_STRING=`./getpostdata.cgi $CONTENT_LENGTH`
		# QUERY_STRING=`./urldecode.cgi $QUERY_STRING`
		if [ "$_method" = "add" ];then
			echo "add"
			QUERY_STRING="IPv6PDEn_mode1=1&bindLanLst=&ipModel=PPPoE&enblNat=0&enVlanMux=1&gainPrefix=0&DslitEnable=0&AftrEnable=0&action=edit&vlanMuxId=41&Aftr=NULL&mtu=1492&pppUserName=$_pppoe_user&pppPassword=$_pppoe_pwd&pppServerName=&wanIpAddress=&wanSubnetMask=&defaultGateway=&dnsPrimary=&dnsSecondary=&v6Gateway=&v6Address=&v6Prefix=&WANv6Prefix=&v6FirstDns=&v6SecondDns=&dialtime=&dial=AlwaysOn&serviceMode=INTERNET&model=Routed&linkModel=ipv4&d8021=0&linkName=0&v6IPAddressOrigin=AutoConfigured&prefixorign=PrefixDelegation"
			# QUERY_STRING="IPv6PDEn_mode1=1&bindLanLst=&ipModel=PPPoE&enblNat=0&enVlanMux=1&gainPrefix=0&DslitEnable=0&AftrEnable=0&action=edit&vlanMuxId=41&Aftr=NULL&mtu=1500&pppUserName=$_pppoe_user&pppPassword=$_pppoe_pwd&pppServerName=NULL&wanIpAddress=&wanSubnetMask=&defaultGateway=&dnsPrimary=&dnsSecondary=&v6Gateway=&v6Address=&v6Prefix=&WANv6Prefix=&v6FirstDns=&v6SecondDns=&dialtime=0&dial=AlwaysOn&serviceMode=INTERNET&model=Routed&linkModel=ipv4&d8021=0&linkName=$_linkname&v6IPAddressOrigin=DHCPv6&prefixorign=PrefixDelegation"
		else 
			echo "del"
			QUERY_STRING="IPv6PDEn_mode1=1&ipModel=2&enblNat=1&enVlanMux=0&gainPrefix=1&action=delete&vlanMuxId=41&mtu=1492&pppUserName=$_pppoe_user&pppPassword=$_pppoe_pwd&pppServerName=NULL&wanIpAddress=&wanSubnetMask=&defaultGateway=&dnsPrimary=&dnsSecondary=&dialtime=0&serviceMode=INTERNET&model=Routed&linkModel=ipv4&d8021=0&dial=AlwaysOn&linkName=$_linkname&v6Gateway=&v6Address=&v6Prefix=&WANv6Prefix=&v6FirstDns=&v6SecondDns=&v6IPAddressOrigin=DHCPv6&prefixorign=PrefixDelegation"
			#QUERY_STRING="IPv6PDEn_mode1=1&ipModel=2&enblNat=0&enVlanMux=0&gainPrefix=1&action=delete&vlanMuxId=41&mtu=1500&pppUserName=$_pppoe_user&pppPassword=$_pppoe_pwd&pppServerName=NULL&wanIpAddress=&wanSubnetMask=&defaultGateway=&dnsPrimary=&dnsSecondary=&dialtime=0&serviceMode=INTERNET&model=Routed&linkModel=ipv4&d8021=0&dial=AlwaysOn&linkName=$_linkname&v6Gateway=&v6Address=&v6Prefix=&WANv6Prefix=&v6FirstDns=&v6SecondDns=&v6IPAddressOrigin=DHCPv6&prefixorign=PrefixDelegation"
		fi
		echo "QUERY_STRING:$QUERY_STRING"
		
if [ -n "$QUERY_STRING" ]; then
    paramIndex="1"
    CGIParam=`echo "$QUERY_STRING&" | cut -d '&' -f $paramIndex`
    while [ "$CGIParam" != "" ]
	do
	  par=`echo "$CGIParam" | cut -d '=' -f 1`
	  val=`echo "$CGIParam" | cut -d '=' -f 2`
	  if [ "$val" == "" ];then
		  val="NULL"
	  fi
	  if [ "$val" != "" ]; then
			case $par
			in
			"action")
			ACTION=$val
			;;
			"linkName")
			LINKNAME=$val
			break
			;;
			esac
	  fi
	  paramIndex=$((paramIndex+1))
	  CGIParam=`echo "$QUERY_STRING&" | cut -d '&' -f $paramIndex`
    done
fi

var_t=`echo "$LINKNAME" | cut -d '_' -f 1`
CHOOSE1=0
CHOOSE2=0
MODE_index=0

for index_1 in 1 2 3 4 5 6 7 8; do
	for index_2 in 1 2; do
		IPC_Enable_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Enable		
		eval IPC_Enable_index=\$$IPC_Enable_index		
		FLAG=`$INTER_WEB get $IPC_Enable_index | cut -d '&' -f 1`
		if [ "$FLAG" == "1" ]; then
			IPC_Name_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Name
			eval IPC_Name_index=\$$IPC_Name_index
			CONNECTNAME_temp=`$INTER_WEB get $IPC_Name_index | cut -d '&' -f 1`
		else
			continue
		fi
		CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`		
		CHOOSE=`echo "$CONNECTNAME_temp" | cut -d '_' -f 1`
		if [ "$CHOOSE" == "$var_t" ]; then
			CHOOSE1=$index_1
			CHOOSE2=$index_2
			MODE_index=1
		fi		
		eval CONNECTNAMEIPC${index_1}${index_2}=$CONNECTNAME_temp
	done
done
		
for index_3 in 1 2 3 4 5 6 7 8; do
	for index_4 in 1 2; do
		PPPC_Enable_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Enable		
		eval PPPC_Enable_index=\$$PPPC_Enable_index		
		FLAG=`$INTER_WEB get $PPPC_Enable_index | cut -d '&' -f 1`
		if [ "$FLAG" == "1" ]; then
			PPPC_Name_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Name
			eval PPPC_Name_index=\$$PPPC_Name_index
			CONNECTNAME_temp=`$INTER_WEB get $PPPC_Name_index | cut -d '&' -f 1`
		else
			continue
		fi
		CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
		CHOOSE=`echo "$CONNECTNAME_temp" | cut -d '_' -f 1`
		if [ "$CHOOSE" == "$var_t" ]; then
			CHOOSE1=$index_3
			CHOOSE2=$index_4
			MODE_index=2
		fi	
		eval CONNECTNAMEPPPC${index_3}${index_4}=$CONNECTNAME_temp	
	done
done

if [ "$ACTION" != "edit" ] && [ ! -z "$ACTION" ]
then
	if [ "$ACTION" == "refurbish" ]; then
		RETURNSTR=`$SETCFG ${BROANCONF} linkname ${LINKNAME}`
		RETURNSTR=`$SETCFG ${BROANCONF} show_Index $var_t`
	else	
		L_IPVX=IGD_WAND_1_WANCD_${CHOOSE1}_X_FIB_COM_IPVX
		eval L_IPVX=\$$L_IPVX
		LINKMODEL_INT_t=`$INTER_WEB get $L_IPVX`	
		RETURNSTR=`$SETCFG ${BROANCONF} show_Index 0`
		RETURNSTR=`$SETCFG ${BROANCONF} linkname 0`
		### for IGMP
		if [ "$LINKMODEL_INT_t" != "2" ]; then
		    modifyIgmpConfig
			modifyMldConfig	
		fi
		###for MLD Proxy
		if [ "$LINKMODEL_INT_t" != "1" ]; then
            modifyMldConfig			
		fi
		### for QoS
#		deleteQosV4 $CHOOSE1 $CHOOSE2
        deleteQosV6 $CHOOSE1 $CHOOSE2
		###delete wan connection
		
		if [ "$MODE_index" == "1" ]; then
			PPPC1_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_1_Enable
			eval PPPC1_Enable_index=\$$PPPC1_Enable_index
			PPPC1_Enable=`$INTER_WEB get $PPPC1_Enable_index | cut -d '&' -f 1`

			PPPC2_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_2_Enable
			eval PPPC2_Enable_index=\$$PPPC2_Enable_index
			PPPC2_Enable=`$INTER_WEB get $PPPC2_Enable_index | cut -d '&' -f 1`		
			
			if [ "$CHOOSE2" == "1" ]; then
				IPC2_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_2_Enable
				eval IPC2_Enable_index=\$$IPC2_Enable_index
				IPC2_Enable=`$INTER_WEB get $IPC2_Enable_index | cut -d '&' -f 1`		
				if [ "$PPPC1_Enable" == "1" ] || [ "$PPPC2_Enable" == "1" ] || [ "$IPC2_Enable" == "1" ]; then
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_1; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`
				else
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`				
				fi
			else
				IPC1_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_1_Enable
				eval IPC1_Enable_index=\$$IPC1_Enable_index
				IPC1_Enable=`$INTER_WEB get $IPC1_Enable_index | cut -d '&' -f 1`		
				if [ "$PPPC1_Enable" == "1" ] || [ "$PPPC2_Enable" == "1" ] || [ "$IPC1_Enable" == "1" ]; then
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_2; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`
				else
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`				
				fi				
			fi
		else
			IPC1_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_1_Enable
			eval IPC1_Enable_index=\$$IPC1_Enable_index
			IPC1_Enable=`$INTER_WEB get $IPC1_Enable_index | cut -d '&' -f 1`

			IPC2_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANIPC_2_Enable
			eval IPC2_Enable_index=\$$IPC2_Enable_index
			IPC2_Enable=`$INTER_WEB get $IPC2_Enable_index | cut -d '&' -f 1`		
			
			if [ "$CHOOSE2" == "1" ]; then
				PPPC2_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_2_Enable
				eval PPPC2_Enable_index=\$$PPPC2_Enable_index
				PPPC2_Enable=`$INTER_WEB get $PPPC2_Enable_index | cut -d '&' -f 1`
				if [ "$IPC1_Enable" == "1" ] || [ "$IPC2_Enable" == "1" ] || [ "$PPPC2_Enable" == "1" ]; then
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_1; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`
				else
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`				
				fi
			else
				PPPC1_Enable_index=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_1_Enable
				eval PPPC1_Enable_index=\$$PPPC1_Enable_index
				PPPC1_Enable=`$INTER_WEB get $PPPC1_Enable_index | cut -d '&' -f 1`	
				if [ "$IPC1_Enable" == "1" ] || [ "$IPC2_Enable" == "1" ] || [ "$PPPC1_Enable" == "1" ]; then
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}_WANPPPC_2; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`
				else
					del_obj=IGD_WAND_1_WANCD_${CHOOSE1}; eval del_obj=\$$del_obj
					RETURN_STR=`$MOREMGT delobj $del_obj`				
				fi				
			fi	
		fi
		#deleteIPv6par $CHOOSE
		logger -t HG260G -p 2 "$sysusername delete one wan connection!"
	fi
fi

if [ "$ACTION" == "edit" ]
then
	paramIndex="1"
	CGIParam=`echo "$QUERY_STRING&" | cut -d '&' -f $paramIndex`
	while [ "$CGIParam" != "" ]
		do
		par=`echo "$CGIParam" | cut -d '=' -f 1`
		val=`echo "$CGIParam" | cut -d '=' -f 2`
		if [ "$val" == "" ];then
		  val="NULL"
	    fi
		if [ "$val" != "" ]; then
		case $par
		in
		    "0")
			grep "broadbund\.cgi:${val}" timestamp.temp >> /dev/null 2>&1
			isRefresh=$?
			if [ "$isRefresh" != "0" ]; then
				grep -v "broadbund.cgi:.*" timestamp.temp > timestamp.temp.temp 2>/dev/null
			    echo "broadbund.cgi:${val}" >> timestamp.temp.temp
				mv timestamp.temp.temp timestamp.temp 2>/dev/null
			else
			    break
			fi
			;;
			"upStream")
			UPSTREAM=$val
			;;
			"linkName")
			LINKNAME=$val
			;;
			"model")
			MODEL=$val
			;;
			"serviceMode")
			SERVICEMODE=$val
			;;
			"ipModel")
			IPMODEL=$val
			;;
			"pppUserName")
			PPPUSERNAME=$val
			;;
			"pppPassword")
			PPPPASSWORD=$val
			;;
			"pppServerName")
			PPPSERVERNAME=$val
			;;
			"pppToBridge")
			PPPTOBRIDGE=$val
			#[ "x$PPPTOBRIDGE" == "x1" ] && PPPTOBRIDGE="Enabled" || PPPTOBRIDGE="Disabled"
			;;
			"enblPppRtProxy")
			ENBLPPPRTPROXY=$val
			;;
			"pppProxyMaxUser")
			PPPPROXYMAXUSER=$val
			;;
			"atmServiceCategory")
			ATMSERVICECATEGORY=$val
			;;
			"atmPeakCellRate")
			ATMPEAKCELLRATE=$val
			;;
			"atmSustainedCellRate")
			ATMSUSTAINEDCELLRATE=$val
			;;
			"atmMaxBurstSize")
			ATMMAXBURSTSIZE=$val
			;;
			"enblNat")
			ENBLNAT=$val
			;;
			"enVlanMux")
			[ "$val" -eq "1" ] && ENVLANMUX=2 || ENVLANMUX=0
			;;
			"vlanMuxId")
			VLANMUXID=$val
			;;
			"mtu")
			MTU=$val
			;;
			"d8021")
			D8021=$val
			;;
			"dial")
			DIAL=$val
			;;
			"dialtime")
			DIALTIME=$val
			;;
			"encapMode")
			ENCAPMODE=$val
			;;
			"bindLanLst")
			BINDLANLST=$val
			;;
			"wanIpAddress")
			WANIPADDRESS=$val
			;;
			"wanSubnetMask")
			WANSUBNETMASK=$val
			;;
			"defaultGateway")
			DEFAULTGATEWAY=$val
			;;
			"dnsPrimary")
			DNSPRIMARY=$val
			;;
			"dnsSecondary")
			DNSSECONDARY=$val
			;;
           "linkModel")
			LINKMODEL=$val
    		if [ "$LINKMODEL" == "ipv4" ]; then
    		   LINKMODEL_INT=1
    		fi
    		if [ "$LINKMODEL" == "ipv6" ]; then
    		   LINKMODEL_INT=2
    		fi
    		if [ "$LINKMODEL" == "ipv4ipv6" ]; then
    		   LINKMODEL_INT=3
    		fi			
			;;
			"v6Gateway")
			V6GATEWAY=$val
			;;
			"v6Address")
			V6ADDRESS=$val
			;;
			"WANv6Prefix")
			WANV6PREFIX=$val
			;;
			"gainPrefix")
			GAINPREFIX=$val
			;;
			"prefixorign")
			PREFIXORIGIN=$val
			;;
			"v6Prefix")
			IPV6PREFIX=$val
			;;
			"v6IPAddressOrigin")
			 GAINADDRESS=$val
			;;
			"v6FirstDns")
			V6FIRSTDNS=$val
			;;
			"v6SecondDns")
			V6SECONDDNS=$val
			;;			
			"DslitEnable")
			DslitEnable=$val
			;;
			"AftrEnable")
			AftrEnable=$val
			;;
			"Aftr")
			Aftr=$val
			;;
			"IPv6PDEn_mode1")
			IPv6PDEn_mode1=$val
			;;				
			esac
			fi
		
		paramIndex=$((paramIndex+1))
		CGIParam=`echo "$QUERY_STRING&" | cut -d '&' -f $paramIndex`
		is_submit="1"
		done
		if [ "$isRefresh" != "0" ]; then
		    [ -z "$BINDLANLST" ] && BINDLANLST="NULL"
		    if [ "$MODEL" == "Bridged" ]; then
			    TMPMODEL=B
			    IPMODEL=PPPoE
		    else
			    TMPMODEL=R
		    fi
            [ -z "$DNSSECONDARY" ] && DNS_XML=$DNSPRIMARY || DNS_XML="$DNSPRIMARY,$DNSSECONDARY"
		else
		    is_submit=0
		fi
fi

if [ "$is_submit" == "1" ]; then
	RETURN_STR=`$INTER_WEB set $IGD_WAND_1_WANCIC_WANAccessType GPON`
	if [ "$LINKMODEL_INT" == "2" ]; then
		WANIPADDRESS="NULL"
		WANSUBNETMASK="NULL"
		DEFAULTGATEWAY="NULL"
		DNS_XML="NULL"
    fi
    if ! echo "$CHOOSE1" | grep -q '^[1-8]$'; then
	    CHOOSE1=`$MOREMGT addobj $IGD_WAND_1_WANCD`
		CHOOSE2=1
	fi
	if echo "$CHOOSE1" | grep -q '^[1-8]$'; then
		calculateCommonKey
		
		if [ "$ENVLANMUX" == "0" ]; then
		    D8021=0
			VLANMUXID=0
		fi
		readwaninterface
		if [ "$IPMODEL" == "DHCP" ]; then
			ipmodel_dhcp
			calculateIPCKey
			var_t=`$INTER_WEB get $IPC_SessionIndex | cut -d '&' -f 1`
		elif [ "$IPMODEL" == "Static" ]; then
			ipmodel_static
			calculateIPCKey
			var_t=`$INTER_WEB get $IPC_SessionIndex | cut -d '&' -f 1`
		elif [ "$IPMODEL" == "PPPoE" ]; then
			ipmodel_pppoe
			calculatePPPCKey
			var_t=`$INTER_WEB get $PPPC_SessionIndex | cut -d '&' -f 1`
		fi
		[ "$SERVICEMODE" == "OTHER" ] && SERVICEMODE="Other" || SERVICEMODE=$SERVICEMODE
		[ "$SERVICEMODE" == "TR069,VOIP,INTERNET" ] && SERVICEMODE="TR069,VOICE,INTERNET" || SERVICEMODE=$SERVICEMODE
		[ "$SERVICEMODE" == "VOIP" ] && SERVICEMODE="VOICE" || SERVICEMODE=$SERVICEMODE
		[ "$SERVICEMODE" == "TR069,VOIP" ] && SERVICEMODE="TR069,VOICE" || SERVICEMODE=$SERVICEMODE
		[ "$SERVICEMODE" == "VOIP,INTERNET" ] && SERVICEMODE="VOICE,INTERNET" || SERVICEMODE=$SERVICEMODE
		if [ "$IPMODEL" == "PPPoE" ]; then
			if [ "$VLANMUXID" == "0" ]; then
				eval CONNECTNAME_temp="${var_t}_${SERVICEMODE}_${TMPMODEL}_VID_"
			else
				eval CONNECTNAME_temp="${var_t}_${SERVICEMODE}_${TMPMODEL}_VID_${VLANMUXID}"
			fi
		else
			if [ "$VLANMUXID" == "0" ]; then
				eval CONNECTNAME_temp="${var_t}_${SERVICEMODE}_${TMPMODEL}_VID_"
			else
				eval CONNECTNAME_temp="${var_t}_${SERVICEMODE}_${TMPMODEL}_VID_${VLANMUXID}"
			fi
		fi
		
		CONNECTNAME=`echo "$CONNECTNAME_temp" | sed 's/,/_/g'`
		CONNECTNAME=`echo "$CONNECTNAME" | sed 's/\,/_/g'`
		RETURNSTR=`$SETCFG ${BROANCONF} linkname ${CONNECTNAME}`
		RETURNSTR=`$SETCFG ${BROANCONF} show_Index ${var_t}`
		### for IGMP adn MLD
		[ "$LINKMODEL_INT_t" != "2" ] && modifyIgmpConfig
		[ "$LINKMODEL_INT_t" != "2" ] && modifyMldConfig
	else
	    FULL_ENTY=1
	fi
fi	
# echo "
# {\"RETURN\":
#   {\"success\": true}
# }"
}


_get_del_linkname(){
	_del_link_name=
	_pppoe_user_index=
	_del_pppoe_name=

	# for index_1 in 1 2 3 4 5 6 7 8; do
	# 	for index_2 in 1 2; do
	# 		IPC_Enable_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Enable
	# 		eval IPC_Enable_index=\$$IPC_Enable_index
	# 		FLAG=`$INTER_WEB get $IPC_Enable_index | cut -d '&' -f 1`
	# 		if [ "$FLAG" == "1" ]; then
	# 			IPC_Name_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Name
	# 			eval IPC_Name_index=\$$IPC_Name_index
	# 			CONNECTNAME_temp=`$INTER_WEB get $IPC_Name_index | cut -d '&' -f 1`
	# 			CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
	# 			_link_idx=`echo $CONNECTNAME_temp | cut -d'_' -f 1`
	# 			_cur_idxs="$_cur_idxs $_link_idx"
	# 			_tmp_internet_r=`echo $CONNECTNAME_temp | grep INTERNET_R`
	# 			if [ "$_tmp_internet_r" != "" ];then
	# 				_has_internet_r=1
	# 			fi
	# 		fi
	# 	done
	# done

	for index_3 in 1 2 3 4 5 6 7 8; do
		for index_4 in 1 2; do
			PPPC_Enable_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Enable		
			eval PPPC_Enable_index=\$$PPPC_Enable_index
			FLAG=`$INTER_WEB get $PPPC_Enable_index | cut -d '&' -f 1`
			if [ "$FLAG" == "1" ]; then
				PPPC_Name_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Name
				_del_pppoe_user_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Username
				eval PPPC_Name_index=\$$PPPC_Name_index
				eval _del_pppoe_user_index=\$$_del_pppoe_user_index
				_del_pppoe_name=`$INTER_WEB get $_del_pppoe_user_index | cut -d '&' -f 1`
				CONNECTNAME_temp=`$INTER_WEB get $PPPC_Name_index | cut -d '&' -f 1`
				CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
				if [ "$_del_pppoe_name" = "$_pppoe_user" ];then
				     _del_link_name=$CONNECTNAME_temp
			         break;
				fi				
			fi
		done
	done


	if [ "$_del_link_name" = "" ];then
	    echo ""
	else
	    echo "$_del_link_name"
	fi
}
_get_add_linkname(){
	_link_idx=0
	_tmp_internet_r=
	_has_internet_r=0
	_cur_idxs=
	_real_link_idx=1

	for index_1 in 1 2 3 4 5 6 7 8; do
		for index_2 in 1 2; do
			IPC_Enable_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Enable
			eval IPC_Enable_index=\$$IPC_Enable_index
			FLAG=`$INTER_WEB get $IPC_Enable_index | cut -d '&' -f 1`
			if [ "$FLAG" == "1" ]; then
				IPC_Name_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Name
				eval IPC_Name_index=\$$IPC_Name_index
				CONNECTNAME_temp=`$INTER_WEB get $IPC_Name_index | cut -d '&' -f 1`
				CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
				_link_idx=`echo $CONNECTNAME_temp | cut -d'_' -f 1`
				_cur_idxs="$_cur_idxs $_link_idx"
				_tmp_internet_r=`echo $CONNECTNAME_temp | grep INTERNET_R`
				if [ "$_tmp_internet_r" != "" ];then
					_has_internet_r=1
				fi
			fi
		done
	done

	for index_3 in 1 2 3 4 5 6 7 8; do
		for index_4 in 1 2; do
			PPPC_Enable_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Enable		
			eval PPPC_Enable_index=\$$PPPC_Enable_index
			FLAG=`$INTER_WEB get $PPPC_Enable_index | cut -d '&' -f 1`
			if [ "$FLAG" == "1" ]; then
				PPPC_Name_index=IGD_WAND_1_WANCD_${index_3}_WANPPPC_${index_4}_Name
				eval PPPC_Name_index=\$$PPPC_Name_index
				CONNECTNAME_temp=`$INTER_WEB get $PPPC_Name_index | cut -d '&' -f 1`
				CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
				_link_idx=`echo $CONNECTNAME_temp | cut -d'_' -f 1`
				_cur_idxs="$_cur_idxs $_link_idx"
				_tmp_internet_r=`echo $CONNECTNAME_temp | grep INTERNET_R`
				if [ "$_tmp_internet_r" != "" ];then
					_has_internet_r=1
				fi
			else
				continue
			fi
		done
	done


	if [ $_has_internet_r -eq 1 ];then
		echo ""
	else
		echo "_cur_idxs:$_cur_idxs"
		for i in $_cur_idxs;do
			if [ "$i" != "$_real_link_idx" ];then
				break;
			fi
			_real_link_idx=`expr $_real_link_idx + 1`
		done
		echo "${_real_link_idx}_INTERNET_R_VID_41"
	fi
}

_get_route_pwd(){
	_ppp_user_index=
	_ppp_user=
	_ppp_pwd_index=
	_ppp_pwd=
	_tmp_internet_r1=

	# for index_1 in 1 2 3 4 5 6 7 8; do
	# 	for index_2 in 1 2; do
	# 		IPC_Enable_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Enable
	# 		eval IPC_Enable_index=\$$IPC_Enable_index
	# 		FLAG=`$INTER_WEB get $IPC_Enable_index | cut -d '&' -f 1`
	# 		if [ "$FLAG" == "1" ]; then
	# 			IPC_Name_index=IGD_WAND_1_WANCD_${index_1}_WANIPC_${index_2}_Name
	# 			eval IPC_Name_index=\$$IPC_Name_index
	# 			CONNECTNAME_temp=`$INTER_WEB get $IPC_Name_index | cut -d '&' -f 1`
	# 			CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
	# 			_link_idx=`echo $CONNECTNAME_temp | cut -d'_' -f 1`
	# 			_cur_idxs="$_cur_idxs $_link_idx"
	# 			_tmp_internet_r=`echo $CONNECTNAME_temp | grep INTERNET_R`
	# 			if [ "$_tmp_internet_r" != "" ];then
	# 				_has_internet_r=1
	# 			fi
	# 		fi
	# 	done
	# done

	for index_5 in 1 2 3 4 5 6 7 8; do
		for index_6 in 1 2; do
			PPPC_Enable_index=IGD_WAND_1_WANCD_${index_5}_WANPPPC_${index_6}_Enable		
			eval PPPC_Enable_index=\$$PPPC_Enable_index
			FLAG=`$INTER_WEB get $PPPC_Enable_index | cut -d '&' -f 1`
			if [ "$FLAG" == "1" ]; then
				PPPC_Name_index=IGD_WAND_1_WANCD_${index_5}_WANPPPC_${index_6}_Name
				_ppp_user_index=IGD_WAND_1_WANCD_${index_5}_WANPPPC_${index_6}_Username
				_ppp_pwd_index=IGD_WAND_1_WANCD_${index_5}_WANPPPC_${index_6}_Password
				eval PPPC_Name_index=\$$PPPC_Name_index
				eval _ppp_user_index=\$$_ppp_user_index
				eval _ppp_pwd_index=\$$_ppp_pwd_index
				
				CONNECTNAME_temp=`$INTER_WEB get $PPPC_Name_index | cut -d '&' -f 1`
				CONNECTNAME_temp=`echo "$CONNECTNAME_temp" | sed 's/ALL/TR069_VOICE_INTERNET/g'`
				_tmp_internet_r1=`echo $CONNECTNAME_temp | grep INTERNET_R`
				if [ "$_tmp_internet_r1" != "" ];then
					_ppp_user=`$INTER_WEB get $_ppp_user_index | cut -d '&' -f 1`
					_ppp_pwd=`$INTER_WEB get $_ppp_pwd_index | cut -d '&' -f 1`
			        break;
				fi				
			fi
		done
	done

	echo "$_ppp_user $_ppp_pwd"
}



if [ $# -eq 0 ];then
	#read
	getbroadbund
	exit 0
else

	#set
	_method=$1
	if [ $# -gt 1 ];then
		_pppoe_user=$2
	else
		_pppoe_user=tzwincg
	fi

	if [ $# -gt 2 ];then
		_pppoe_pwd=$3
	else
		_pppoe_pwd="tzwincg123"
	fi

	if [ "$_method" = "add" ];then
        _linkname=`_get_add_linkname`
		if [ "$_linkname" = "" ];then
			exit 0
		else
			# echo "$_linkname"
			setbroadbund
		fi
	elif [ "$_method" = "get_route_pwd" ];then
		_get_route_pwd
	else
        echo del 
		_linkname=`_get_del_linkname`
		if [ "$_linkname" = "" ];then
			exit 0
		else
			# echo "$_linkname"
			setbroadbund
		fi
	fi
	
fi
